﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using System.Text.RegularExpressions;
using System.Windows.Media.Imaging;
using System.Windows;

namespace Kiosk.Library
{
    public partial class NotificationInfo
    {
        public string LocationName
        {
            get
            {
               return Library.Location.GetLocation(this.LocationID).Name;                
            }
        }

        public Point LocationPoint
        { 
            get
            {
                LocationInfo l = LocationInfo.GetLocationInfoById(this.LocationID);
                return new Point(l.XCoordinate, l.YCoordinate);
            }
        }

        public EmployeeInfo Employee
        {
            get
            {
                EmployeeInfo emp = EmployeeInfo.GetEmployeeInfoById(this.EmployeeID);
                return emp;
            }
        }

        public string NotificationTypeName
        {
            get
            {
                return NotificationTypeReadOnlyList.GetAll().Single(nt => nt.NotificationTypeID == this.NotificationTypeID).Name;
            }
        }

        public BitmapImage IconFile
        {
            get
            {
                string text = this.Title + this.Description;
                text = Regex.Replace(text, "\\s+", "").ToLower();
                Uri loc = Library.IconReadOnlyList.FindIconFileByKeyword(text);

                if (loc == null)
                {
                    // get the default icon
                    loc = new Uri("images/" + this.NotificationTypeName.ToLower() + ".png", UriKind.Relative);
                }
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = loc;
                bi.CacheOption = BitmapCacheOption.OnLoad;
                bi.EndInit();
                return bi;


            }
        }
    }
}
